<template>
<div>
  <div>
    <el-container class="home_container">
      <el-header>
        <div>
          <img src="../assets/logo.png" alt="">
          <span>电商后台管理系统</span>
        </div>
        <el-button type='info' @click="logout">退出</el-button>
      </el-header>
      <el-container>
<!--        动态绑定要加 :-->
          <SideMenu :menu-list="menuList"></SideMenu>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>

  </div>
</div>
</template>

<script>
import SideMenu from "@/components/SideMenu";

export default {
  name: "Home",
  data(){
   return{
     menuList:[],
   }
  },
  components: { SideMenu},
  created() {
    this.getMenuList()
  },
  methods:{
    logout(){
      //清除token
      window.sessionStorage.clear()

      //跳转到登录页
      this.$router.push('./login')
    },
    async getMenuList(){
      const {data:res} = await this.$axios.get('menus')
        //console.log(res)
      if(res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menuList = res.data
    }
  }
}
</script>

<style lang="less" scoped>
.home_container{
  /*position: absolute;*/
  /*vh是屏幕的1%，设置为全屏，元素中没有内容时，若设置为100%，则不生效*/
  height: 100vh;
}
.el-header{
  background-color: #373d41;
  padding-left: 10px;
  display: flex;
  //设置在主轴上的布局
  justify-content: space-between;
  //使里面的元素不贴边，居中
  //设置交叉轴的布局
  align-items: center;
  //设置文本颜色
  color:#fff;
  //字体大小
  font-size: 21px;
  div{
    display: flex;
    align-items: center;
    span{
      margin-left: 21px;
    }
  }
  img{
    width:36px;
    height: 36px;
    border-radius: 50%;
  }
}


.el-main{
  background-color: #eaedf1;
}
</style>